package ro.upt.dcda.web.admin;

import java.util.Map;

import ro.upt.dcda.pricezone.s1.pojo.Admin;
import ro.upt.dcda.pricezone.s1.requests.admin.AdminLogoutRequest;

import com.opensymphony.xwork2.ActionContext;

public class AdminLogoutServlet {

	public String execute() throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		Admin admin = (Admin) session.get("admin");
		String sid = (String) session.get("adminSid");
		if (admin == null || sid == null) {
			System.out.println("Invalid logout requested:"+sid);
			return "def";
		}
		AdminLogoutRequest logout = new AdminLogoutRequest();
		if (logout.work(admin.getEmail(), sid)) {
			session.remove("admin");
			session.remove("adminSid");
			session.remove("email");
			System.out.println("Succesful logout 2");
		} else {
			System.out.println("Failed logout");
		}
		return "def";
	}
}
